// @ts-ignore
/* eslint-disable */
import request from '@/request'
import type { AxiosRequestConfig } from 'axios'


/** 用户上传头像接口 POST /api/file/upload/userAvatar */
export async function uploadUserAvatarUsingPost(
  body: {},
  file?: File,
  options?: { [key: string]: any }
) {
  const fileFormData = new FormData()

  if (file) {
    fileFormData.append('file', file)
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele]

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => fileFormData.append(ele, f || ''))
        } else {
          fileFormData.append(ele, JSON.stringify(item))
        }
      } else {
        fileFormData.append(ele, item)
      }
    }
  })

  interface CustomAxiosRequestConfig extends AxiosRequestConfig {
    requestType?: string;
  }

  return request<API.BaseResponseString_>('/api/file/upload/userAvatar', {
    method: 'POST',
    data: fileFormData,
    requestType: 'form',
    ...(options || {}),
  }as CustomAxiosRequestConfig)
}
